//package com.xingkeduo.delayQueue.service;
//
//import com.xingkeduo.delayQueue.model.Task;
//import com.xingkeduo.delayQueue.model.TaskModel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.util.concurrent.DelayQueue;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
///**
// * @author chi  2019-02-22 15:41
// **/
//
//@Component
//@Slf4j
//public class MemoryTaskService implements TaskService {
//    private ExecutorService executorService = Executors.newCachedThreadPool();
//
//    private DelayQueue<Task> delayQueue = new DelayQueue<>();
//
//    @PostConstruct
//    protected void consumeMessage() {
//        executorService.execute(this::transferFromDelayQueue);
//    }
//
//    @Override
//    public void addToDeplayQueue(TaskModel taskModel) {
//        log.info("addToDeplayQueue:{}", taskModel);
//        Task task = taskModel.covertToTask();
//        delayQueue.add(task);
//    }
//
//    @Override
//    public boolean removeFromDeplayQueue(TaskModel taskModel) {
//        Task task = taskModel.covertToTask();
//        delayQueue.remove(task);
//        return true;
//    }
//
//    // 模拟任务处理队列
//
//
//    public void transferFromDelayQueue() {
//        while (true) {
//            try {
//                Thread.sleep(1000);
//                if (delayQueue.size() == 0) {
//                    continue;
//                }
//                Task first = delayQueue.take();
//                addToTaskQue(first.getId(), first.getValue()); //任务推入延时队列，因为这里只是延时
//
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
//    }
//
//}
